// 导入 vue
import Vue from 'vue'
// 导入 vuex
import Vuex from 'vuex'
import user from './modules/user'
import { getIndex } from '@/api'
// vuex也是vue的插件, 需要use一下, 进行插件的安装初始化
Vue.use(Vuex)

// 创建仓库 store
const store = new Vuex.Store(
  {
    state: {
      allCate: [],
      allTag:[]
    },
    mutations: {
      updateCate (state, newCate) {
        state.allCate = newCate
      },
      updateTag (state, newTag) {
        state.allTag = newTag
      }

    },
    actions: {
      async cateAction (context) {
        const res = await getIndex()
        context.commit('updateCate', res.data.allCate)
        context.commit('updateTag', res.data.allTag)
      }
    },
    getters: {},
    modules: {
      user
    }
  }
)

// 导出仓库
export default store